﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using Panel=System.Web.UI.WebControls.Panel;

namespace EventumReports
{
    public partial class _Default : System.Web.UI.Page
    {
        #region props

        private Color AAGDarkOrange = Color.FromArgb(245, 131, 31);
        private Color AAGDarkGrey = Color.FromArgb(77, 77, 77);
        private Color AAGDarkBlue = Color.FromArgb(0, 112, 192);
        private Color AAGDarkMustard = Color.FromArgb(253, 144, 17);
        private Color AAGDarkPurple = Color.FromArgb(102, 0, 52);
        private Color AAGDarkGreen = Color.FromArgb(0, 153, 52);
        private Color AAGDarkCanaryYellow = Color.FromArgb(252, 214, 12);
        private Color AAGDarkBrown = Color.FromArgb(99,66,00);
        private Color AAGDarkSeaGreen = Color.FromArgb(51,153,153);
        //private Color AAGLightOrange = Color.FromArgb(200, 245, 131, 31);
        //private Color AAGLightGrey = Color.FromArgb(200, 77, 77, 77);
        //private Color AAGLightBlue = Color.FromArgb(200, 0, 112, 192);
        //private Color AAGLightMustard = Color.FromArgb(200, 253, 144, 17);
        //private Color AAGLightPurple = Color.FromArgb(200, 102, 0, 52);
        //private Color AAGLightGreen = Color.FromArgb(200, 0, 153, 52);
        //private Color AAGLightCanaryYellow = Color.FromArgb(200, 252, 214, 12);

        private Color[] AAGColorPalette;

        #endregion

        #region events

        protected void Page_Load(object sender, EventArgs e)
        {
//            AAGColorPalette = new Color[] { AAGDarkOrange, AAGDarkGrey, AAGDarkBlue, AAGLightOrange, AAGLightGrey, AAGLightBlue, AAGMustard, Color.WhiteSmoke, Color.Black };
            AAGColorPalette = new Color[]
                                  {
                                      AAGDarkOrange, AAGDarkGrey, AAGDarkBlue, AAGDarkMustard, AAGDarkPurple,
                                      AAGDarkGreen, AAGDarkCanaryYellow, AAGDarkBrown, AAGDarkSeaGreen, Color.WhiteSmoke, Color.Black//, AAGLightOrange, AAGLightGrey, AAGLightBlue,
                                      //AAGLightMustard, AAGLightPurple, AAGLightGreen, AAGLightCanaryYellow
                                  };
            
            if (!IsPostBack)
            {
                cbCategories.DataSource = EventumCategory.GetCategories();
                cbCategories.DataTextField = "Name";
                cbCategories.DataValueField = "Id";
                cbCategories.DataBind();

                cbProjects.DataSource = EventumProject.GetProjects();
                cbProjects.DataTextField = "Name";
                cbProjects.DataValueField = "Id";
                cbProjects.DataBind();

                cbStatuses.DataSource = EventumStatus.GetStatusses();
                cbStatuses.DataTextField = "Name";
                cbStatuses.DataValueField = "Id";
                cbStatuses.DataBind();

                cbUsers.DataSource = EventumUser.GetUsers();
                cbUsers.DataTextField = "Name";
                cbUsers.DataValueField = "Id";
                cbUsers.DataBind();

                txtStartDate.Text = DateTime.Now.AddDays(-7).ToShortDateString();
                txtEndDate.Text = DateTime.Now.ToShortDateString();
            }
        }

        protected void btnGenerateReport_Click(object sender, EventArgs e)
        {
            List<string> categories = new List<string>();
            foreach (ListItem item in cbCategories.Items)
            {
                if (item.Selected)
                {
                    categories.Add(item.Text);
                }
            }

            List<string> projects = new List<string>();
            foreach (ListItem item in cbProjects.Items)
            {
                if (item.Selected)
                {
                    projects.Add(item.Text);
                }
            }

            List<string> statusses = new List<string>();
            foreach (ListItem item in cbStatuses.Items)
            {
                if (item.Selected)
                {
                    statusses.Add(item.Text);
                }
            }

            List<long> users = new List<long>();
            foreach (ListItem item in cbUsers.Items)
            {
                if (item.Selected)
                {
                    users.Add(long.Parse(item.Value));
                }
            }

            SearchCriteria searchCriteria = new SearchCriteria();
            searchCriteria.Categories = categories.ToArray();
            searchCriteria.Projects = projects.ToArray();
            searchCriteria.Statusses = statusses.ToArray();
            searchCriteria.Users = users.ToArray();

            try
            {
                searchCriteria.StartDate = DateTime.Parse(txtStartDate.Text);
                searchCriteria.EndDate = DateTime.Parse(txtEndDate.Text);
            }
            catch
            {
                searchCriteria.StartDate = DateTime.Now.AddDays(-7);
                searchCriteria.EndDate = DateTime.Now;
            }

            GetReports(searchCriteria);
        }

        #endregion

        #region reports

        private void GetReports(SearchCriteria searchCriteria)
        {
            ReportInfo _reportInfo = new ReportInfo();
            List<ReportInfo> _reportInfos = _reportInfo.GetReportInfo(searchCriteria);

            if (cbProjectCategoryStatus.Checked)
            {
                ProjectCategoryStatus(_reportInfos);
            }

            if (cbProjectUserCategory.Checked)
            {
                ProjectUserCategory(_reportInfos);
            }

            if (cbProjectUserStatus.Checked)
            {
                ProjectUserStatus(_reportInfos);
            }

            if (cbProjectCategory.Checked)
            {
                ProjectCategory(_reportInfos);
            }

            if (cbProjectStatus.Checked)
            {
                ProjectStatus(_reportInfos);
            }

            if(trend.Checked)
            {
                BugsClosedPreviousMonthPerDay(_reportInfos);
            }
        }

        private void ProjectCategoryStatus(List<ReportInfo> _reportInfos)
        {
            try
            {

            
            Panel panel = new Panel();
            panel.BackColor = RandomColor();
            panel.Style.Add("Padding", "10px");

            List<EventumProject> _eventumProjects = (from pl in _reportInfos select pl.EventumProject).ToList();
            List<long> eventumProjectIds = (from p in _eventumProjects select p.Id).Distinct().ToList();
            foreach (long eventumProjectId in eventumProjectIds)
            {
                EventumProject eventumProject = (from ep in _eventumProjects where ep.Id == eventumProjectId select ep).FirstOrDefault();
                Chart chart = new Chart();

                Title title = new Title(eventumProject.Name);
                chart.Titles.Add(DrawTitle(title));

                ChartArea ca = new ChartArea(eventumProject.Name);
                ca.AxisX.Title = "Category";
                ca.AxisY.Title = "Status/Total";
                chart.ChartAreas.Add(DrawChartArea(ca));

                List<EventumCategory> _eventumCategories = (from s in _reportInfos where s.EventumProject.Id == eventumProject.Id select s.EventumCategory).ToList();
                List<long> _eventumCateglongoryIds = (from ec in _eventumCategories select ec.Id).Distinct().ToList();
                foreach (long eventumCategoryId in _eventumCateglongoryIds)
                {
                    if(eventumCategoryId != null && eventumCategoryId > 0)
                    {
                        EventumCategory eventumCategory = (from ec in _eventumCategories where ec.Id == eventumCategoryId select ec).FirstOrDefault();

                        Series series = new Series(eventumCategory.Name);
                        chart.Series.Add(DrawSeries(series));

                        Legend legend = new Legend(eventumCategory.Name);
                        chart.Legends.Add(DrawLegend(legend));

                        List<EventumStatus> _eventumStatuses = (from s in _reportInfos where s.EventumProject.Id == eventumProject.Id && s.EventumCategory.Id == eventumCategoryId select s.EventumStatus).ToList();
                        List<long> eventumStatusIds = (from es in _eventumStatuses select es.Id).Distinct().ToList();

                        foreach (long eventumStatusId in eventumStatusIds)
                        {
                            EventumStatus eventumStatus = (from es in _eventumStatuses where es.Id == eventumStatusId select es).FirstOrDefault();
                            if (!string.IsNullOrEmpty(eventumStatus.Name))
                            {
                                double count = (from c in _reportInfos where c.EventumCategory.Id == eventumCategory.Id && c.EventumProject.Id == eventumProject.Id && c.StatusId == eventumStatusId select c).Count();
                                chart.Series[eventumCategory.Name].Points.AddXY(eventumStatus.Name, count);
                                chart.Series[eventumCategory.Name]["StackGroupName"] = eventumCategory.Name;
                            }
                        }
                    }
                   
                }
                if (_eventumCategories.Count > 0)
                    panel.Controls.Add(DrawChart(chart));
            }
            ph.Controls.Add(panel);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        private void ProjectUserCategory(List<ReportInfo> _reportInfos)
        {
            Panel panel = new Panel();
            panel.BackColor = RandomColor();
            panel.Style.Add("Padding", "10px");

            List<EventumProject> _eventumProjects = (from pl in _reportInfos select pl.EventumProject).ToList();
            List<long> eventumProjectIds = (from p in _eventumProjects select p.Id).Distinct().ToList();
            foreach (long eventumProjectId in eventumProjectIds)
            {
                EventumProject eventumProject = (from ep in _eventumProjects where ep.Id == eventumProjectId select ep).FirstOrDefault();
                Chart chart = new Chart();

                Title title = new Title(eventumProject.Name);
                chart.Titles.Add(DrawTitle(title));
                //try
                //{
                //    FileInfo fi = new FileInfo(Server.MapPath(string.Format("Images/{0}_sml.png", eventumProject.Name)));
                //    if(fi.Exists)
                //    chart.BackImage = string.Format("Images/{0}_sml.png", eventumProject.Name);
                //}
                //catch (Exception)
                //{
                //}
                

                ChartArea ca = new ChartArea(eventumProject.Name);
                ca.AxisX.Title = "Status";
                ca.AxisY.Title = "Total";
                chart.ChartAreas.Add(DrawChartArea(ca));
                
                List<EventumUser> _eventumUsers = new List<EventumUser>();

                foreach (List<EventumUser> userlist in (from ri in _reportInfos where ri.ProjectId == eventumProjectId select ri.EventumUsers))
                {
                    foreach (EventumUser eventumUser in userlist)
                    {
                        _eventumUsers.Add(eventumUser);
                    }
                }

                foreach (EventumUser eventumUser in _eventumUsers.Distinct(u => u.Name))
                {
                    List<EventumStatus> _eventumStatuses = (from ec in _reportInfos where ec.EventumUsers.ToArray().Any(eu => eu.Name.Contains(eventumUser.Name)) select ec.EventumStatus).ToList();
                    List<long> eventumStatusIds = (from es in _eventumStatuses select es.Id).Distinct().ToList();

                    Series series = new Series(eventumUser.Name);
                    chart.Series.Add(DrawSeries(series));

                    Legend legend = new Legend(eventumUser.Name);
                    chart.Legends.Add(DrawLegend(legend));

                    foreach (long eventumStatusId in eventumStatusIds)
                    {
                        EventumStatus eventumStatus =
                            (from es in _eventumStatuses where es.Id == eventumStatusId select es).FirstOrDefault();
                        

                        double count = (from cc in _reportInfos
                                        where
                                            cc.EventumProject.Id == eventumProjectId &&
                                            cc.EventumUsers.ToArray().Any(eu => eu.Name.Contains(eventumUser.Name)) &&
                                            cc.EventumStatus.Id == eventumStatusId
                                        select cc.Id).Count();

                        if(count > 0)
                        chart.Series[eventumUser.Name].Points.AddXY(eventumStatus.Name, count);
                    }
                }
                
                if (_eventumUsers.Count > 0)
                {
                    panel.Controls.Add(DrawChart(chart));
                    SaveImage(chart);
                }
            }
            ph.Controls.Add(panel);
        }

        private void ProjectUserStatus(List<ReportInfo> _reportInfos)
        {
            //List<string> projects = (from reportInfo in _reportInfos select reportInfo.Project).Distinct().ToList();

            //foreach (string project in projects)
            //{
            //    Chart Chart1 = new Chart();

            //    Title t = new Title(project);
            //    Chart1.Titles.Add(DrawTitle(t));

            //    ChartArea ca = new ChartArea("Series 1");
            //    Chart1.ChartAreas.Add(DrawChartArea(ca));


            //    List<string> statusses = (from tp in _reportInfos where tp.Project == project select tp.Status).Distinct().ToList();
            //    foreach (string status in statusses)
            //    {
            //        if (!string.IsNullOrEmpty(status))
            //        {
            //            Series series = new Series(status);
            //            Chart1.Series.Add(DrawSeries(series));
            //            List<string> users = (from u in _reportInfos where u.Project == project && u.Status == status select u.AssignedTo.FirstOrDefault()).Distinct().ToList();
            //            foreach (string user in users)
            //            {
            //                double count = (from gt in _reportInfos where gt.AssignedTo.FirstOrDefault() == user && gt.Project == project && gt.Status == status select gt.Id).Count();
            //                if (!string.IsNullOrEmpty(user))
            //                {
            //                    Chart1.Series[status].Points.AddXY(user, count);
            //                    Chart1.Series[status]["StackGroupName"] = user;
            //                }
            //            }
            //        }
            //    }

            //    Legend legend = new Legend("Legend1");
            //    Chart1.Legends.Add(DrawLegend(legend));

            //    ph.Controls.Add(DrawChart(Chart1));
            //}
        }

        private void ProjectCategory(List<ReportInfo> _reportInfos)
        {
            Panel panel = new Panel();
            panel.BackColor = RandomColor();
            panel.Style.Add("Padding", "10px");

            List<EventumProject> _eventumProjects = (from pl in _reportInfos select pl.EventumProject).ToList();
            List<long> eventumProjectIds = (from p in _eventumProjects select p.Id).Distinct().ToList();
            foreach (long eventumProjectId in eventumProjectIds)
            {
                EventumProject eventumProject = (from ep in _eventumProjects where ep.Id == eventumProjectId select ep).FirstOrDefault();
                Chart chart = new Chart();
                //try
                //{
                //    FileInfo fi = new FileInfo(Server.MapPath(string.Format("Images/{0}_sml.png", eventumProject.Name)));
                //    if (fi.Exists)
                //        chart.BackImage = string.Format("Images/{0}_sml.png", eventumProject.Name);
                //}
                //catch (Exception)
                //{
                //}

                Title title = new Title(eventumProject.Name);
                chart.Titles.Add(DrawTitle(title));

                ChartArea ca = new ChartArea(eventumProject.Name);
                ca.AxisX.Title = "Status";
                ca.AxisY.Title = "Total";
                chart.ChartAreas.Add(DrawChartArea(ca));

                Series series = new Series(eventumProject.Name);
                chart.Series.Add(DrawSeries(series));

                //Legend legend = new Legend(eventumProject.Name);
                //chart.Legends.Add(DrawLegend(legend));

                List<EventumCategory> _eventumCategories = (from s in _reportInfos where s.EventumProject.Id == eventumProject.Id select s.EventumCategory).ToList();
                List<long> _eventumCateglongoryIds = (from ec in _eventumCategories select ec.Id).Distinct().ToList();
                foreach (long eventumCategoryId in _eventumCateglongoryIds)
                {
                    EventumCategory eventumCategory = (from ec in _eventumCategories where ec.Id == eventumCategoryId select ec).FirstOrDefault();
                    if (!string.IsNullOrEmpty(eventumCategory.Name))
                    {
                        double count = (from c in _reportInfos where c.EventumCategory.Id == eventumCategory.Id && c.EventumProject.Id == eventumProject.Id select c).Count();
                        if (count > 0)
                        chart.Series[eventumProject.Name].Points.AddXY(eventumCategory.Name, count);
                        //chart.Series[eventumCategory.Name]["StackGroupName"] = eventumCategory.Name;
                    }
                }
                if (_eventumCategories.Count > 0)
                {
                    panel.Controls.Add(DrawChart(chart));
                    SaveImage(chart);
                }
            }
            ph.Controls.Add(panel);
        }

        private void ProjectStatus(List<ReportInfo> _reportInfos)
        {
            Panel panel = new Panel();
            panel.BackColor = RandomColor();
            panel.Style.Add("Padding", "10px");

            List<EventumProject> _eventumProjects = (from pl in _reportInfos select pl.EventumProject).ToList();
            List<long> eventumProjectIds = (from p in _eventumProjects select p.Id).Distinct().ToList();
            foreach (long eventumProjectId in eventumProjectIds)
            {
                EventumProject eventumProject = (from ep in _eventumProjects where ep.Id == eventumProjectId select ep).FirstOrDefault();
                Chart chart = new Chart();
                //try
                //{
                //    FileInfo fi = new FileInfo(Server.MapPath(string.Format("Images/{0}_sml.png", eventumProject.Name)));
                //    if (fi.Exists)
                //        chart.BackImage = string.Format("Images/{0}_sml.png", eventumProject.Name);
                //}
                //catch (Exception)
                //{
                //}

                Title title = new Title(eventumProject.Name);
                chart.Titles.Add(DrawTitle(title));

                ChartArea ca = new ChartArea(eventumProject.Name);
                ca.AxisX.Title = "Status";
                ca.AxisY.Title = "Total";
                chart.ChartAreas.Add(DrawChartArea(ca));

                Series series = new Series(eventumProject.Name);
                chart.Series.Add(DrawSeries(series));

                //Legend legend = new Legend(eventumProject.Name);
                //chart.Legends.Add(DrawLegend(legend));

                List<EventumStatus> _eventumStatuses = (from s in _reportInfos where s.EventumProject.Id == eventumProject.Id select s.EventumStatus).ToList();
                List<long> eventumStatusIds = (from es in _eventumStatuses select es.Id).Distinct().ToList();
                foreach (long eventumStatusId in eventumStatusIds)
                {
                    EventumStatus eventumStatus = (from es in _eventumStatuses where es.Id == eventumStatusId select es).FirstOrDefault();
                    if (!string.IsNullOrEmpty(eventumStatus.Name))
                    {
                        double count = (from c in _reportInfos where c.EventumStatus.Id == eventumStatus.Id && c.EventumProject.Id == eventumProject.Id select c.Id).Count();
                        if (count > 0) 
                            chart.Series[eventumProject.Name].Points.AddXY(eventumStatus.Name, count);
                        //chart.Series[eventumStatus.Name]["StackGroupName"] = eventumStatus.Name;
                    }
                }
                if (_eventumStatuses.Count>0)
                {
                    panel.Controls.Add(DrawChart(chart));
                    SaveImage(chart);
                }
            }
            ph.Controls.Add(panel);
        }

        private void SaveImage(Chart chart)
        {
            string chartParth = Path.Combine(Server.MapPath("Charts"),
                                             DateTime.Now.Year + "_" + DateTime.Now.Month + "_" +
                                             DateTime.Now.Day + "_" + DateTime.Now.Hour);

            DirectoryInfo di = new DirectoryInfo(chartParth);
            Random r = new Random();
            if (di.Exists)
            {
                chart.SaveImage(chartParth + "/" + r.Next(1, 100000000) + ".png");
            }
            else
            {
                di.Create();
                chart.SaveImage(chartParth + "/" + r.Next(1, 100000000) + ".png");
            }
        }

        #endregion

        #region trend reports 

        private void BugsClosedPreviousMonthPerDay(List<ReportInfo> _reportInfos)
        {
            Panel panel = new Panel();
            panel.BackColor = RandomColor();
            panel.Style.Add("Padding", "10px");


            List<EventumProject> _eventumProjects = (from pl in _reportInfos select pl.EventumProject).ToList();
            List<long> eventumProjectIds = (from p in _eventumProjects select p.Id).Distinct().ToList();
            foreach (long eventumProjectId in eventumProjectIds)
            {
                EventumProject eventumProject =
                    (from ep in _eventumProjects where ep.Id == eventumProjectId select ep).FirstOrDefault();
                Chart chart = new Chart();

                Title title = new Title(eventumProject.Name);
                chart.Titles.Add(DrawTitle(title));

                ChartArea ca = new ChartArea(eventumProject.Name);
                ca.AxisX.Title = "Status";
                ca.AxisY.Title = "Total";
                chart.ChartAreas.Add(DrawChartArea(ca));

                Series Open = new Series("Open");
                chart.Series.Add(DrawSeries(Open));

                Series Closed = new Series("Closed");
                chart.Series.Add(DrawSeries(Closed));

                Legend legend = new Legend("X");
                chart.Legends.Add(DrawLegend(legend));

                string[] statusses = (from reportInfo in _reportInfos select reportInfo.EventumCategory.Name).Distinct().ToArray();
                List<ReportInfo> sortedList = (from reportInfo in _reportInfos select reportInfo).OrderBy(ob => ob.DateCreated).ToList();
                DateTime _minMonth = sortedList.FirstOrDefault().DateCreated;
                DateTime _maxMonth = sortedList.LastOrDefault().DateCreated;

                int days = _maxMonth.Subtract(_minMonth).Days;

                for (int i = 0; i < days; i++)
                {
                    DateTime _currentDay = _minMonth.AddDays(i);

                    double _closed = (from c in _reportInfos
                                               where
                                                   c.EventumCategory.Name == "Bug" &&
                                                   (
                                                        c.EventumStatus.Name == "closed" ||
                                                        c.EventumStatus.Name == "released" ||
                                                        c.EventumStatus.Name == "completed" ||
                                                        c.EventumStatus.Name == "killed" ||
                                                        c.EventumStatus.Name == "parked"
                                                   ) &&
                                                   c.EventumProject.Id == eventumProject.Id &&
                                                   (
                                                        c.DateCreated.ToShortDateString() == _currentDay.ToShortDateString() ||
                                                        c.DateClosed.ToShortDateString() == _currentDay.ToShortDateString() ||
                                                        c.DateAction1.ToShortDateString() == _currentDay.ToShortDateString() ||
                                                        c.DateAction2.ToShortDateString() == _currentDay.ToShortDateString() ||
                                                        c.DateAction3.ToShortDateString() == _currentDay.ToShortDateString() ||
                                                        c.DateAction4.ToShortDateString() == _currentDay.ToShortDateString()
                                                   )
                                               select c.Id).Count();

                    chart.Series["Closed"].Points.AddXY(_currentDay.ToShortDateString(), _closed);
                    chart.Series["Closed"].ChartType = SeriesChartType.Spline;
                    chart.Series["Closed"].IsValueShownAsLabel = false;
                    chart.Series["Closed"].MarkerStyle = MarkerStyle.Diamond;
                    chart.Series["Closed"].MarkerSize = 7;


                    double _open = (from c in _reportInfos
                                    where
                                        c.EventumCategory.Name == "Bug" &&
                                        c.DateCreated.ToShortDateString() == _currentDay.ToShortDateString()
                                    select c.Id).Count();

                    chart.Series["Open"].Points.AddXY(_currentDay.ToShortDateString(), _open);
                    chart.Series["Open"].ChartType = SeriesChartType.Spline;
                    chart.Series["Open"].IsValueShownAsLabel = false;
                    chart.Series["Open"].MarkerStyle = MarkerStyle.Diamond;
                    chart.Series["Open"].MarkerSize = 7;
                }

                panel.Controls.Add(DrawChart(chart));
            }
            ph.Controls.Add(panel);
        }

        #endregion

        #region *** UI ***

        public Chart DrawChart(Chart chart)
        {
            chart.Height = 600;
            chart.Width = 800;
            chart.BackGradientStyle = GradientStyle.None;
            chart.BackColor = Color.Black;
            //chart.Palette = ChartColorPalette.None;
            //chart.PaletteCustomColors = AAGColorPalette;
            return chart;
        }

        public Title DrawTitle(Title title)
        {
            title.Alignment = ContentAlignment.TopLeft;
            title.ForeColor = Color.White;
            title.Font = new Font("Trebuchet MS", 14, FontStyle.Bold);

            return title;
        }

        public Legend DrawLegend(Legend legend)
        {
            legend.LegendStyle = LegendStyle.Column;
            legend.BackColor = Color.Transparent;
            legend.ForeColor = Color.White;
            return legend;
        }

        public ChartArea DrawChartArea(ChartArea chartArea)
        {
            chartArea.AxisX.TitleForeColor = Color.White;
            chartArea.AxisY.TitleForeColor = Color.White;
            chartArea.AxisX.LabelStyle.ForeColor = Color.White;
            chartArea.AxisY.LabelStyle.ForeColor = Color.White;
            chartArea.BackColor = Color.DarkGray;
            chartArea.BackGradientStyle = GradientStyle.None;
            
            //chartArea.BorderColor = Color.White;
            //chartArea.BackSecondaryColor = Color.DarkGray;
            //chartArea.BackColor = Color.DarkGray;
            //chartArea.ShadowColor = Color.Transparent;
            //chartArea.BackGradientStyle = GradientStyle.None;
            //chartArea.AxisY.LineColor = Color.White;
            //chartArea.AxisX.LineColor = Color.White;
            
            chartArea.AxisX.Interval = 1;
            //chartArea.AxisX.IsLabelAutoFit = false;
            chartArea.AxisX.LabelStyle.Angle = -90;
            //chartArea.AxisY.LabelStyle.ForeColor = Color.White;
            //chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;

            //chartArea.Area3DStyle.IsRightAngleAxes = true;
            chartArea.Area3DStyle.IsClustered = true;
            //chartArea.Area3DStyle.Inclination = 10;
            //chartArea.Area3DStyle.Inclination = 10;
            //chartArea.Area3DStyle.Enable3D = true;
            //chartArea.Area3DStyle.LightStyle = LightStyle.Realistic;

           
            return chartArea;
        }

        public Series DrawSeries(Series series)
        {
            series.BackGradientStyle = GradientStyle.VerticalCenter;
            series.ChartType = SeriesChartType.StackedColumn;
            series.IsValueShownAsLabel = true;

            //series.BackSecondaryColor = Color.Gray;
            //series.BorderColor = Color.Gray;
            //series.BorderWidth = 1;
            //series.BorderDashStyle = ChartDashStyle.Solid;
            //series.ShadowOffset = 3;
            //series.LabelForeColor = Color.Black;
            

            return series;
        }

        public Color RandomColor()
        {
            Random random = new Random();
            int r = random.Next(0, 255);
            int g = random.Next(0, 255);
            int b = random.Next(0, 255);

            return Color.FromArgb(r, g, b);
        }

        #endregion
    }
}